package right_content_config

import "fyne.io/fyne/v2"

func init() {
	RegisterRightContent("MysqlConfig", &MysqlConfig{}, true)
	RegisterRightContent("OtherConfig", &OtherConfig{}, false)
	RegisterRightContent("OracleConfig", &OracleConfig{}, false)
}

type rightContent interface {
	// 装载内容
	LadeContent()
	//获取内容
	GetContent() fyne.CanvasObject
}

// map[string]rightContent
var RightContentMap = make(map[string]rightContent)

// 注册右侧内容
func RegisterRightContent(name string, rightContent rightContent, show bool) {
	//判断是否已经注册
	if _, ok := RightContentMap[name]; ok {
		panic(name + "已经注册过了")
	}
	//装载内容
	rightContent.LadeContent()
	if !show {
		rightContent.GetContent().Hide()
	}
	RightContentMap[name] = rightContent
}

// 获取右侧内容
func GetRightContent(name string) fyne.CanvasObject {
	if rightContent, ok := RightContentMap[name]; ok {
		return rightContent.GetContent()
	}
	panic("GetRightContent-》未找到" + name + "的内容")
}

// 获取所有右侧内容
func GetAllRightContent() []fyne.CanvasObject {
	var allContent []fyne.CanvasObject
	for _, content := range RightContentMap {
		allContent = append(allContent, content.GetContent())
	}
	return allContent
}

// 隐藏所有
func HideAllRightContent() {
	for _, content := range RightContentMap {
		content.GetContent().Hide()
	}
}
